<template>
  <Layout class="p-5 bg-white">
    <Form :label-width="80" class="p-5">
      <Row>
        <Col span="9" push="5">
          <FormItem class="w-100" label="回访人">
            <Select
              placeholder="请选择回访人"
              v-model="searchAutor"
              filterable
              clearable
            >
              <Option v-for="item in autorList" :value="item.value"
                >{{ item.label }}
              </Option>
            </Select>
          </FormItem>
          <FormItem class="w-100" label="回访日期">
            <Date-picker
              format="yyyy-MM-dd HH:mm:ss"
              class="w-100"
              :value="this.$route.params.row.backviewDateTime"
              type="datetime"
              placeholder="回访时间"
              @on-change="updateBackviewDateTime"
            >
            </Date-picker>
          </FormItem>

          <FormItem class="w-100" label="回访方式">
            <Input
              v-model="backview.method"
              placeholder="请输入回访方式"
            ></Input>
          </FormItem>

          <FormItem class="w-100" label="回访类型">
            <Input v-model="backview.type" placeholder="请输入回访类型"></Input>
          </FormItem>

          <FormItem class="w-100" label="回访描述">
            <Input
              type="textarea"
              v-model="backview.des"
              :autosize="{ minRows: 4, maxRows: 8 }"
              placeholder="请输入回访描述"
            ></Input>
          </FormItem>

          <FormItem class="w-100" label="回访结果">
            <Input
              v-model="backview.result"
              placeholder="请输入回访结果"
            ></Input>
          </FormItem>

          <FormItem class="text-right">
            <Button @click="submit" type="primary">提交</Button>
            <Button @click="cancel" class="ml-2">取消</Button>
          </FormItem>
        </Col>
      </Row>
    </Form>
	<Loadding v-bind:loadinghuan="isSpinShow"></Loadding>
  </Layout>
</template>

<script>
export default {
  data() {
    return {
	  isSpinShow:false,
      autorList: [],
      searchAutor: this.$route.params.row.autorId,
      backview: {
        id: null,
        type: '',
        autor: null,
        des: '',
        result: '',
        dateTime: '',
        stage: '',
        method: '',
        cu: null,
        ct: '',
        uu: null,
        ut: '',
      },
      allStages: [],
    }
  },
  methods: {
    updateBackviewDateTime(updateBackviewTime) {
      this.backview.dateTime = updateBackviewTime
    },
    submit: function() {
      let _this = this
      let id = this.$route.params.row.backviewId
      let des = _this.backview.des
      let result = _this.backview.result
      let dateTime = '' + _this.backview.dateTime
      let method = _this.backview.method
      let autor = _this.searchAutor


      var backview = {
        'backview.id': id,
        'backview.autor': autor,
        'backview.des': des,
        'backview.result': result,
        'backview.dateTime': dateTime,
        'backview.method': method,
      }
	  this.isSpinShow = true
      this.http
        .put({
          url: '/backview',
          param: backview,
        })
        .then((data) => {
			this.isSpinShow = false
          _this.message.info('修改成功')
          _this.$tabs.close()
        })
    },
    cancel: function() {
      this.$tabs.close()
    },
  },
  destroyed: function() {
    this.$router.push({
      name: 'backview',
    })
  },
  created: function() {
    let _this = this
    _this.backview.autor = this.$route.params.row.autor
    _this.backview.des = this.$route.params.row.des
    _this.backview.result = this.$route.params.row.result
    _this.backview.dateTime = this.$route.params.row.backviewDateTime
    _this.backview.method = this.$route.params.row.method
    _this.backview.stage = this.$route.params.row.stage
    _this.backview.type = this.$route.params.row.type

    //初始化跟进人人下拉框
    let userList = JSON.parse(localStorage.getItem('USER_LIST'))
    userList.forEach((user) => {
      let u = {
        value: user.userId,
        label: user.nickName,
      }
      this.autorList.push(u)
    })
  },
}
</script>
